package ${package}.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import yyy.ab.common.core.BaseController;
import yyy.ab.common.core.ResultBean;
import ${package}.entity.${className};
import ${package}.service.${className}Service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
* @author ${author}
* @date ${date}
*/
@RestController
@RequiredArgsConstructor
@Api(tags = "${apiAlias}管理")
@RequestMapping("/${apiPath}/${changeClassName}")
public class ${className}Controller extends BaseController {

    private final ${className}Service ${changeClassName}Service;

    @Log("${apiAlias}页面")
    @ApiOperation("${apiAlias}页面")
    @RequestMapping
    @PreAuthorize("@ab.check('${changeClassName}:list')")
    public ModelAndView jump() {
        ModelAndView view = new ModelAndView();
        view.setViewName("${apiPath}/${changeClassName}/index");
        return view;
    }

    @GetMapping("/findPage")
    @Log("查询${apiAlias}")
    @ApiOperation("查询${apiAlias}")
    @PreAuthorize("@ab.check('${changeClassName}:list')")
    public Object query(@RequestParam Map<String, Object> params){
        IPage<${className}> page = service.findPage(params);
        return jsonForTable(page);
    }

    @ApiOperation("查询单个${apiAlias}")
    @GetMapping("/get")
    public ${className} get(Long id) {
        ${className} ${changeClassName} = service.getById(id);
        return appModule;
    }

    @PostMapping
    @Log("新增${apiAlias}")
    @ApiOperation("新增${apiAlias}")
    @PreAuthorize("@ab.check('${changeClassName}:add')")
    public Object create(@RequestBody ${className} ${changeClassName}){
        ResultBean resultBean = ${changeClassName}Service.create(${changeClassName}));
        return resultBean;
    }

    @PutMapping
    @Log("修改${apiAlias}")
    @ApiOperation("修改${apiAlias}")
    @PreAuthorize("@ab.check('${changeClassName}:edit')")
    public Object update(@RequestBody ${className} ${changeClassName}){
        ResultBean resultBean = ${changeClassName}Service.update(${changeClassName});
        return resultBean;
    }

    @Log("删除${apiAlias}")
    @ApiOperation("删除${apiAlias}")
    @PreAuthorize("@ab.check('${changeClassName}:del')")
    @DeleteMapping
    public ResponseEntity<Object> deleteAll(@RequestBody ${pkColumnType}[] ids) {
        List<Long> idList = Arrays.asList(ids);
        ResultBean resultBean = ${changeClassName}Service.deleteAll(idList);
        return resultBean;
    }
}